/*
输出日志的函数有几个[没加ln的不用，作为现在的C++ glog的替换，注意参数保持一致，以方便后续的操作]
		func (l *Logger) Fatalf(format string, v ...interface{})
		func (l *Logger) Fatalln(v ...interface{})
		func (l *Logger) Output(calldepth int, s string) error
		func (l *Logger) Panicf(format string, v ...interface{})
		func (l *Logger) Panicln(v ...interface{})
		func (l *Logger) Printf(format string, v ...interface{})
		func (l *Logger) Println(v ...interface{})
具体的使用例子
	Info.Println("Special Information")
	Warning.Println("There is something you need to know about")
	Error.Println("Something has failed")
*/
package common

import (
	"io"
	"log"
	"os"
)

var (
	debug   *log.Logger // Just about anything
	info    *log.Logger // Important information
	warning *log.Logger // Be concerned
	error   *log.Logger // Critical problem
)

func init() {
	file, err := os.OpenFile("errors.txt",
		os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	if err != nil {
		log.Fatalln("Failed to open error log file:", err)
	}

	debug = log.New(os.Stdout, //ioutil.Discard,
		"DEBUG: ",
		log.Ldate|log.Ltime|log.Llongfile)

	info = log.New(os.Stdout,
		"INFO: ",
		log.Ldate|log.Ltime|log.Lshortfile)

	warning = log.New(os.Stdout,
		"WARNING: ",
		log.Ldate|log.Ltime|log.Llongfile)

	error = log.New(io.MultiWriter(file, os.Stderr),
		"ERROR: ",
		log.Ldate|log.Ltime|log.Llongfile)
}

func Log() *log.Logger {
	logs := map[int]*log.Logger{0: debug, 1: info, 2: warning, 3: error}
	return logs[CmdFlags.minloglevel]
}
